﻿using UnityEngine;

namespace CornerMemo
{
    
    public class UIFormEscape : UIForm
    {
        private void OnEnable()
        {
            EventCenter.SubscribeUnique(KeyboardDownEventArgs.EventId, BindKeyDown);
        }

        private void BindKeyDown(object sender, GameEventArgs e)
        {
            if (e is not KeyboardDownEventArgs args)return;
            if (args.KeyCode == KeyCode.Escape)
            {
                Close();
            }
        }

        private void OnDisable()
        {
            EventCenter.Unsubscribe(KeyboardDownEventArgs.EventId, BindKeyDown);
        }
    }
}